package example.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import example.item.Item;
import example.exception.adminException;
import example.service.AService;

@Api("事项管理")
@RestController
@RequestMapping("Item")
public class Controller {
    @Autowired
    AService aService;

    @ApiOperation("根据Id查询物品")
    @GetMapping("/get/{id}")
    public Item getItemById(@PathVariable long id) throws adminException {
        return aService.getItem(id);
    }

    @ApiOperation("添加物品")
    @PostMapping("/add")
    public Item addItem(@RequestBody Item item){
        return aService.addItem(item);
    }

    @ApiOperation("修改物品")
    @PutMapping("/update/{id}")
    public void updateProduct(@PathVariable long id,@RequestBody Item item) throws adminException {
        aService.updateItem(id, item);
    }

    @ApiOperation("删除物品")
    @DeleteMapping("/{id}")
    public void deleteProduct(@PathVariable long id) throws adminException {
        aService.deleteItem(id);
    }

}
